#pragma once

#include "fxcc/core/pch.h"

namespace fs = std::filesystem;

namespace fxcc
{

	struct FXCC_API   FileHeader {

		int m_CreateTime;
		int m_UpdateTime;
		std::string m_CreateBy;
		std::string m_UpdateBy;
		std::string m_Path;
		std::string m_Filename;

		void SetFullPath(const std::string& p)
		{
			fs::path _p(p);
			if (_p.has_parent_path())
			{
				m_Path = _p.parent_path().string();

			}
			else
			{
				m_Path = "./";
			}
			m_Filename = _p.filename().string();
		}

		std::string GetFullPath()
		{
			fs::path p = fs::path(m_Path) / fs::path(m_Filename);
			return p.string();

		}
		FileHeader()
		{
			OnCreate();

		}
		std::string Path()
		{
			if (m_Path.empty())
			{
				return "./";
			}
			return m_Path;
		}
		std::string FileName()
		{
			if (m_Filename.empty())
			{
				return "default.e2d";
			}
			return m_Filename;
		}

		void OnCreate() {
			m_CreateBy = GetUser();
			m_CreateTime = CurrentTime();

		}
		void OnUpdate()
		{
			m_UpdateBy = GetUser();
			m_UpdateTime = CurrentTime();
		}
		bool Empty()
		{
			return m_Path.empty() || m_Filename.empty();
		}
		static std::string GetUser()
		{
			const char* res = std::getenv("USERNAME");
			if (res)
			{
				return res;
			}
			else
			{
				return "";
			}
		}
		static int CurrentTime()
		{
			auto now = std::chrono::system_clock::now();
			auto duration = now.time_since_epoch();
			auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
			return static_cast<int>(millis);

		}
	};
};
